package cn.xshi.sys.service.impl;
import java.util.List;
import java.util.Map;

import cn.xshi.sys.init.GlobalPersistentComponent;
import cn.xshi.sys.model.SysConstant;
import cn.xshi.sys.service.SysConstantService;
import cn.xshi.sys.dao.SysConstantDao;
import org.springframework.stereotype.Service;
import cn.xshi.common.base.BaseService;
import cn.xshi.common.util.ExceptionUtil;
import javax.annotation.Resource;
/**
 * @Desc 常量
 * @Author 邓纯杰
 * @CreateTime 2012-12-12 12:12:12
 */
@Service
public class SysConstantServiceImpl extends BaseService implements SysConstantService {

	@Resource
	private SysConstantDao sysConstantDao;

	@Resource
    GlobalPersistentComponent globalPersistentComponent;

	/**
	* 分页
	* @param condition 
	* @return
	*/
	public List<SysConstant> getSysConstantListByCondition(Map<String,Object> condition){
		try {
			return sysConstantDao.getSysConstantListByCondition(condition);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
	}

	/**
	* 查询对象
	* @param xt_constant_id 
	* @return
	*/
	public SysConstant getSysConstantById(String xt_constant_id){
		try {
			return sysConstantDao.getSysConstantById(xt_constant_id);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
	}

	/**
	* 添加
	* @param sysConstant
	* @return
	*/
	public int addSysConstant(SysConstant sysConstant){
		int i = 0;
		try {
			sysConstant.setCreateTime(getDate());
			sysConstant.setCreateId(getCurrentAccountId());
			i = sysConstantDao.addSysConstant(sysConstant);
			globalPersistentComponent.initSysConstant();
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}

	/**
	* 修改
	* @param sysConstant
	* @return
	*/
	public int updateSysConstant(SysConstant sysConstant){
		int i = 0;
		try {
			sysConstant.setUpdateId(getCurrentAccountId());
			sysConstant.setUpdateTime(getDate());
			i = sysConstantDao.updateSysConstant(sysConstant);
			globalPersistentComponent.initSysConstant();
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}

	/**
	* 删除
	* @param condition 
	* @return
	*/
	public int delSysConstant(Map<String,Object> condition){
		int i = 0;
		try {
			i = sysConstantDao.delSysConstant(condition);
			globalPersistentComponent.initSysConstant();
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}

	/**
	 * 查询常量集合
	 * @param condition
	 * @return
	 */
	public List<SysConstant> getSysConstantListAllByCondition(Map<String,Object> condition){
		try {
			return sysConstantDao.getSysConstantListAllByCondition(condition);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
	}
}
